package common

import (
	"emicro_test/emicro_3/grpc_server/user/utils"
	"github.com/asim/go-micro/v3"
	"github.com/astaxie/beego/config"
	"log"
	"strings"
)

//服务名
const (
	ServerName = "emicro.user"
)

//服务
type EmicroService struct {
	Service micro.Service
	Host string
	Port uint
	Addr string
}

//配置
var Config config.Configer

//请求返回类型
const(
	RESP_SUCCESS = 1
	RESP_ERROR = 2
)

func init () {
	iniConfig, err := config.NewConfig("ini", "./conf/service.conf")
	if err != nil {
		log.Println("Config Init Err:", err)
	}
	Config = iniConfig
}

//创建服务
func NewService() *EmicroService{
	service := new(EmicroService)
	return service
}

//初始化服务器地址
func InitAddr(service *EmicroService) {
	service.Addr = service.Service.Server().Options().Address
	args := strings.Split(service.Service.Server().Options().Address, ":")
	if len(args) == 2 {
		service.Host = args[0]
		service.Port = uint(utils.GetInt(args[1]))
	}
}